using System;
using System.Configuration;
using System.Text;
using System.Web.UI;
using SouthernLand.Common;
using SouthernLand.Common.BOL.Contact;

namespace SouthernLand.Controls
{
    public partial class Contact : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btSend_Click(object sender, ImageClickEventArgs e)
        {
            var obj = new Common.BOL.Contact.Contact();
            obj.ContactID = 0;
            obj.CateID = 1; 
            obj.FullName = txtFullName.Text;
            obj.Address = txtAddress.Text;
            obj.Tel = txtTel.Text;
            obj.Email = txtEmail.Text;
            obj.Title = txtTitle.Text;
            obj.Content = txtContent.Text;
            obj.AddedDate = DateTime.Now;
            Common.BOL.Contact.Contact.Insert(obj);

            PanelMsg.Visible = true;
            lblMsg.Text = ResourceManager.GetString("Contact_SendSuccessfully");
            ContactSetting contact = ContactSetting.GetContactSettingByID(1);
            string EmailTo = contact.Email;
            var sendmail = new SendMail();
            sendmail.MailServer = ConfigurationManager.AppSettings["SmtpServer"];
            sendmail.MailFrom = ConfigurationManager.AppSettings["EmailFrom"];
            sendmail.MailTo = EmailTo;
            sendmail.Subject = "Thu lien he duoc goi tu website: " +
                               ConfigurationManager.AppSettings["Domain"];

            // noi dung can goi
            var strBody = new StringBuilder(string.Empty);
            strBody.AppendLine("<br>");
            strBody.Append("<br> Full Name: " + obj.FullName);
            strBody.AppendLine("<br>");
            strBody.Append("<br> Email: " + obj.Email);
            strBody.AppendLine("<br>");
            strBody.Append("<br> Phone: " + obj.Tel);
            strBody.AppendLine("<br>");
            strBody.AppendLine("<br>");
            strBody.Append("<br> Title: " + obj.Title);
            strBody.AppendLine("<br>");
            strBody.Append(obj.Title);
            sendmail.Body = strBody.ToString();
            //SendMail.Send(sendmail);

            Form_Clear();
        }

        protected void Form_Clear()
        {
            txtFullName.Text = "";
            txtAddress.Text = "";
            txtTel.Text = "";
            txtEmail.Text = "";
            txtTitle.Text = "";
            txtContent.Text = "";
        }
    }
}